using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace _3Dto2D;

public class App
{
    private readonly ILogger<App> _logger;
    private readonly IServiceProvider _serviceProvider;

    public App(IServiceProvider serviceProvider)
    {
        _serviceProvider = serviceProvider;
        _logger = serviceProvider.GetRequiredService<ILogger<App>>();
    }

    public void Run()
    {
        _logger.LogInformation("Application starting...");

        try
        {
            var form = new Main(_serviceProvider);
            Application.Run(form);
        }
        catch (Exception ex)
        {
            _logger.LogCritical(ex, "Application failed to start");
            MessageBox.Show($"Application failed to start: {ex.Message}", 
                "Startup Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}
